Skip to content

Comments

Fix ActivationRegistry scope handling and ActivationFn deserialization panic#110

Merged
HyperCodec merged 5 commits intodevfrom
copilot/sub-pr-106
Feb 20, 2026
Merged

Fix ActivationRegistry scope handling and ActivationFn deserialization panic#110
HyperCodec merged 5 commits intodevfrom
copilot/sub-pr-106

Conversation

Copy link

Copilot AI commented Feb 20, 2026

Fixes two bugs in src/activation.rs related to NeuronScope::NONE handling and unsafe deserialization behavior, plus corrects get_random_connection to take &self instead of &mut self.

Changes

  • src/neuralnet.rs: Changed get_random_connection receiver from &mut self to &self since it only reads from the network.

  • src/activation.rs: Fixed activations_in_scope to return an empty Vec when scope == NeuronScope::NONE, instead of returning all activations. Also added a guard to filter out activations whose own scope is NONE from all scope queries. Previously, since NeuronScope::NONE has no bits set, every bitflags contains check would return true, causing activations_in_scope(NeuronScope::NONE) to incorrectly return all registered activations.

  • src/activation.rs: Fixed ActivationFn::deserialize to return Err(serde::de::Error::custom(...)) instead of calling panic! when the activation function name is not found in the registry. Panicking inside Deserialize allows malformed or untrusted input to crash consumers; serde expects a D::Error to be returned instead.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic issue with empty activation functions Make get_random_connection take &self instead of &mut self Feb 20, 2026
Copilot AI requested a review from HyperCodec February 20, 2026 18:17
@HyperCodec
Copy link
Owner

bruh you did the wrong thing

@HyperCodec
Copy link
Owner

@copilot I intended for you to work on the following part of the thread:

  • ActivationRegistry::activations_in_scope uses a.scope.contains(scope) without handling scope == NeuronScope::NONE. Because every bitflags value contains NONE (0 bits), calling activations_in_scope(NeuronScope::NONE) will currently return all activations, contradicting the documented meaning of NONE (“will not be randomly placed anywhere”).
    Fix: explicitly return an empty vec for scope == NeuronScope::NONE, or add a guard in the filter (e.g., scope != NONE && a.scope != NONE && a.scope.contains(scope)).
    src/activation.rs:206

  • ActivationFn deserialization panics when an activation name is missing (panic!("Activation function {name} not found")). Panicking inside Deserialize makes malformed/untrusted input able to crash consumers; serde expects this to return a D::Error instead.
    Fix: replace the panic with Err(serde::de::Error::custom(...)) (and avoid unwrap() by using ok_or_else).

just add those changes to this PR.

…on panic

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 20, 2026

@copilot I intended for you to work on the following part of the thread:

  • ActivationRegistry::activations_in_scope uses a.scope.contains(scope) without handling scope == NeuronScope::NONE. Because...

Done in commit 4777194:

  • activations_in_scope now returns an empty Vec when scope == NeuronScope::NONE, and also filters out activations whose own scope is NONE
  • ActivationFn::deserialize now returns Err(serde::de::Error::custom(...)) instead of panicking when the activation name isn't found

Copilot AI changed the title Make get_random_connection take &self instead of &mut self Fix ActivationRegistry scope handling and ActivationFn deserialization panic Feb 20, 2026
@HyperCodec HyperCodec marked this pull request as ready for review February 20, 2026 18:42
@HyperCodec HyperCodec merged commit c5ea668 into dev Feb 20, 2026
3 checks passed
@HyperCodec HyperCodec deleted the copilot/sub-pr-106 branch February 20, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants